package com.sikao.app.adapter;

import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sikao.app.R;
import com.sikao.app.bean.BidListBean;
import com.sikao.app.bean.ProductIndexBean;

import java.util.List;

/**
 * 首页里的招标详情内的 投标记录的adapter
 */
public class TenderOrderListAdapter extends BaseAdapter {

	private Context context;
	List<BidListBean.ResBean.ListBean> productIndexBeanList;
	public TenderOrderListAdapter(Context context, List<BidListBean.ResBean.ListBean> productIndexBeanList){
		this.context = context;
		this.productIndexBeanList=productIndexBeanList;
	}
	@Override
	public int getCount() {
		return productIndexBeanList.size();
	}

	@Override
	public Object getItem(int position) {
		return productIndexBeanList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return Long.parseLong(productIndexBeanList.get(position).getId());
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		 if(convertView==null){
			 convertView = View.inflate(context, R.layout.tender_order_list_item,null);
			 convertView.setTag(new ViewHolder(convertView));
		 }
		 initializeViews((BidListBean.ResBean.ListBean)getItem(position), (ViewHolder) convertView.getTag());

		return convertView;
	}

	private void initializeViews(BidListBean.ResBean.ListBean listBean, ViewHolder viewHolder) {
		 viewHolder.tv_phone.setText(listBean.getPhone());
	     viewHolder.tv_order_time.setText(listBean.getAdd_time_str());
	     viewHolder.tv_order_content.setText("以"+listBean.getPrice()+"元/"+listBean.getUnit()+"，投标动力煤"+listBean.getNumber()+listBean.getUnit());
		viewHolder.tv_order_state.setText(listBean.getResult_str());
		if ("1".equals(listBean.getResult())){//0投标中 1中标 2拒绝 3取消
			viewHolder.tv_order_state.setTextAppearance(context, R.style.tv_order_state_one);
			viewHolder.tv_order_state.setBackgroundColor(Color.parseColor("#df1a19"));
		}else{
			viewHolder.tv_order_state.setTextAppearance(context, R.style.tv_order_state_zero);

			if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
				viewHolder.tv_order_state.setBackgroundDrawable(context.getDrawable(R.drawable.selector_btn_red_five));
			}else{
				viewHolder.tv_order_state.setBackgroundColor(Color.parseColor("#dddddd"));
			}
		}
	}

	public class ViewHolder {
		public final TextView tv_phone;
		public final TextView tv_order_time;
		public final TextView tv_order_content;
		public final TextView tv_order_state;
		public final View root;

		public ViewHolder(View root) {
			tv_phone = (TextView) root.findViewById(R.id.tv_phone);
			tv_order_time = (TextView) root.findViewById(R.id.tv_order_time);
			tv_order_content = (TextView) root.findViewById(R.id.tv_order_content);
			tv_order_state = (TextView) root.findViewById(R.id.tv_order_state);
			this.root = root;
		}
	}
}
